[MFC] What is the reciprocal of CComboBox.GetItemData?

Posted by Hamish Grubijan on Stack Overflow See other posts from Stack Overflow or by Hamish Grubijan
Published on 2010-04-12T21:00:18Z Indexed on 2010/04/12 21:03 UTC
Read the original article Hit count: 254

Filed under:
|
|

Instead of associating objects with Combo Box items, I associate long ids representing choices. They come from a database, so it seems natural to do so anyway. Now, I persist the id and not the index of the user's selection, so that the choice is remembered across sessions. If id no longer exists in database - no big deal. The choice will be messed up once. If db does not change, however, then it would be a great success ;)

Here is how I get the id :

chosenSomethingIndex = cmbSomething.GetCurSel();
lastSomethingId = cmbSomething.GetItemData(chosenSomethingIndex);

How do I reverse this? When I load the stored value for user's last choice, I need to convert that id into an index. I can do:

cmbSomething.SetCurSel(chosenSomethingIndex);

However, how can I attempt (it might not exist) to get an index once I have an id?

I am looking for a reciprocal function to GetItemData

I am using VS2008, probably latest version of MFC, whatever that is.

Thank you.

© Stack Overflow or respective owner

Related posts about c++

Related posts about mfc